import tank, math, pygame
#from tank import TankAction

class Agent:
    """
    Agent is an abstract class. Every agent should extend it and implement at least 
    its getAction method, redefining __init__ only if there is need for more variables
    to be stored.
    """
    def __init__(self, index=0):
        self.index = index
    
    def getAction(self):
        """
        Returns the appropriate Action for agent corresponding to index.
        """
        sys.exit(1)

class KeyboardAgent( Agent ):
    """
    Implements a default keyboard agent.
    """

    def getAction(self):
        action = tank.TankAction()
        pressed = pygame.key.get_pressed()
        pygame.event.pump()
        if pressed[pygame.K_UP]:
            action.goForward()
        elif pressed[pygame.K_DOWN]:
            action.goReverse()
        if pressed[pygame.K_LEFT]:
            action.turnLeft()
        elif pressed[pygame.K_RIGHT]:
            action.turnRight()
        if pressed[pygame.K_SPACE]:
            action.shootBullet()
        return action
    
class IdleAgent( Agent ):
    """
    Implements a do-nothing agent.
    """
    
    def getAction(self):
        action = tank.TankAction()
        return action
